package game.mechanics;

import game.util.Die;

import java.util.ArrayList;
import java.util.List;

public class Damage {
	
	private List<Die> dice = new ArrayList<Die>();
	private int[] base;
	
	/**
	 * 
	 * @param base
	 * @param dice d4,d7,2d2
	 */
	public Damage(int[] base, String diceStr) {
		this.base = base;
		
		String[] dice = diceStr.split(",");
		for (int i = 0; i < dice.length; i ++) {
			if (dice[i].indexOf("d") > 0) {
				String[] trolo = dice[i].split("d");
				this.dice.add(new Die(Integer.parseInt(trolo[1]), 
						Integer.parseInt(trolo[0])));
			} else
				this.dice.add(new Die(Integer.parseInt(dice[i].substring(1)), 1));
		}
	}

	public int getDamageValue() {
		int dmg = 0;
		for(int a : base)
		{
			dmg += a;
		}				
		for (Die die : dice)
			dmg += die.roll();
		return dmg;
	}

}
